package com.fosu.dao;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zqa
 * @version 1.0
 * @date 2020/10/20 12:39
 */
@Mapper
@Repository
public interface ProductImgDao {
    /**
     * 根据首页用户传入的商品id获得图片组
     * @param productId 商品id
     * @return List<String> 图片组的url字串集合
     */
    @Results(id = "img", value = {
            @Result(property = "imgUrl", column = "img_url")
    })
    @Select("select img_url " +
            "from product_imgs " +
            "where product_id=#{productId}")
    List<String> findImgsById(int productId);



    /**
     * 插入图片url
     * @param productId 商品id
     * @param imgUrl 要插入的图片url
     */
    @Results(id = "imgMap", value = {
            @Result(property = "productId", column = "product_id"),
            @Result(property = "imgUrl", column = "img_url")
    })
    @Insert("insert into product_imgs(product_id,img_url) values(#{productId},#{imgUrl})")
    void save(int productId,String imgUrl);

    /**
     * 清除所有与商品有关的图片url
     * @param productId 商品id
     */
    @Delete("delete from product_imgs where product_id=#{productId}")
    void clean(int productId);
}
